<html>
<head><meta charset="utf-8"><title>char into string · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/char.20into.20string.html">char into string</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="201213027"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/char%20into%20string/near/201213027" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matthiaskrgr <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/char.20into.20string.html#201213027">(Jun 17 2020 at 23:26)</a>:</h4>
<p>Hi, I found out that </p>
<div class="codehilite"><pre><span></span><code>pub fn char_into_string() -&gt; String {
    &#39;x&#39;.into()
}
</code></pre></div>


<p>Does not work</p>
<div class="codehilite"><pre><span></span><code> &#39;x&#39;.into()

  |         ^^^^ the trait `std::convert::From&lt;char&gt;` is not implemented for `std::string::String`
</code></pre></div>


<p>while <code>'x'.to_string()</code> works fine.</p>
<p>Are there any objections to making this work?</p>



<a name="201216428"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/char%20into%20string/near/201216428" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matthiaskrgr <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/char.20into.20string.html#201216428">(Jun 18 2020 at 00:18)</a>:</h4>
<p>would something like this be enough?</p>
<div class="codehilite"><pre><span></span><code><span class="cp">#[stable(feature = </span><span class="s">&quot;from_char_for_string&quot;</span><span class="cp">, since = </span><span class="s">&quot;1.46.0&quot;</span><span class="cp">)]</span><span class="w"></span>
<span class="k">impl</span><span class="w"> </span><span class="nb">From</span><span class="o">&lt;</span><span class="kt">char</span><span class="o">&gt;</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="nb">String</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="cp">#[inline]</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">from</span><span class="p">(</span><span class="n">c</span>: <span class="kt">char</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">c</span><span class="p">.</span><span class="n">to_string</span><span class="p">()</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="201216444"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/char%20into%20string/near/201216444" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matthiaskrgr <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/char.20into.20string.html#201216444">(Jun 18 2020 at 00:18)</a>:</h4>
<p>(+ some tests of course..)</p>



<a name="201221222"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/char%20into%20string/near/201221222" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/char.20into.20string.html#201221222">(Jun 18 2020 at 01:58)</a>:</h4>
<p>yeah should be good</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>